package com.hellogood.yaohuo.server.serviceImpl;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.hellogood.yaohuo.server.mgr.factory.MgrFactory;
import com.hellogood.yaohuo.shared.entity.Form;
import com.hellogood.yaohuo.shared.entity.YhForm;
import com.hellogood.yaohuo.shared.services.YaohuoService;

public class YaohuoServiceImpl extends RemoteServiceServlet implements YaohuoService {
	private static final long serialVersionUID = 1026305747687394878L;

	@Override
	public List<Form> searchYaohuoFormByOrgCodeAndDate(String orgCode, int level, String startDate, String endDate, String rz) {
		return MgrFactory.getInstance().createYaohuoMgr().searchYhForm(orgCode, level, startDate, endDate, rz);
	}

	@Override
	public Form getFormDetail(String billNo) {
		return MgrFactory.getInstance().createYaohuoMgr().getFormDetail(billNo);
	}

	@Override
	public String deleteForm(String billNo) {
		return MgrFactory.getInstance().createYaohuoMgr().deleteYaohuo(billNo);
	}

	@Override
	public String saveForm(YhForm form, boolean isModify) {
		if (isModify) {
			return MgrFactory.getInstance().createYaohuoMgr().modifyYaohuoForm(form);
		} else {
			return MgrFactory.getInstance().createYaohuoMgr().createYaohuoForm(form);
		}
	}

	@Override
	public String bankForm(List<String> bills) {
		return MgrFactory.getInstance().createYaohuoMgr().rz(bills);
	}

	@Override
	public String getLastYhBillNo(String orgCode) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		DecimalFormat df = new DecimalFormat("0000");
		String billNo = "WLYH" + sdf.format(new Date());
		int lastNo = MgrFactory.getInstance().createYaohuoMgr().getLastYhBillNo(billNo);
		lastNo++;
		billNo += df.format(lastNo);
		return billNo;
	}

}
